package cc.wfu.domain.user.event;

import cc.wfu.types.event.BaseEvent;
import cc.wfu.types.snow.SnowflakeIdGenerator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author: jia-qiang ljq1024.cc
 * @desc: 发送用户上次登录时间的MQ消息
 * @Date: 2024-05-20-20:54
 */
@Component
public class UserLastLoginMessageEvent extends BaseEvent<String> {

    @Value("${spring.rabbitmq.topic.user_last_login_time}")
    private String topic;

    @Resource
    private SnowflakeIdGenerator snowflakeIdGenerator;

    @Override
    public EventMessage<String> buildEventMessage(String data) {
        return EventMessage.<String>builder().data(data)
                .id(String.valueOf(snowflakeIdGenerator.nextId()))
                .timestamp(new Date())
                .build()
                ;
    }

    @Override
    public String topic() {
        return topic;
    }
}
